<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>后台</title>

    <link href="/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
    <link href="/dist/css/sb-admin-2.css" rel="stylesheet">
    <link href="/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="/css/bootstrap-switch.min.css">

    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div id="wrapper">
    <!-- 导航 -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <?php require __DIR__ . '/_nav.php' ?>
    </nav>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">统计</h1>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-4">
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th>位置</th>
                            <th>数量</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($homeStatArray as $statHash) {?>
                            <tr>
                                <td><?php echo $statHash['name'] ?></td>
                                <td><?php echo $statHash['stat'] ?></td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="col-lg-4">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">直播开关</label>
                        <div class="col-sm-8">
                            <input class="switch" id="btn-live-switch" type="checkbox" <?php if($liveSwitch)echo 'checked'; ?> data-on-text="开" data-off-text="关">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">抽奖开关</label>
                        <div class="col-sm-8">
                            <input class="switch" id="btn-lottery-switch" type="checkbox" <?php if($lotterySwitch)echo 'checked'; ?> data-on-text="开" data-off-text="关">
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/vendor/metisMenu/metisMenu.min.js"></script>
<script src="/vendor/raphael/raphael.min.js"></script>
<script src="/dist/js/sb-admin-2.js"></script>
<script src="/js/bootstrap-switch.min.js"></script>
<script>
    $('.switch').bootstrapSwitch();

    $('#btn-live-switch').on('switchChange.bootstrapSwitch', function(e, state) {
        if (confirm('是否更改？')) {
            $.post('/g-admin/liveSwitch', {'switch': state}, function(resp) {
                if (resp.code != 0) {
                    alert(resp.msg);
                    $(this).bootstrapSwitch('state', !state, true);
                }
            });
        } else {
            $(this).bootstrapSwitch('state', !state, true);
        }
    });

    $('#btn-lottery-switch').on('switchChange.bootstrapSwitch', function(e, state) {
        if (confirm('是否更改？')) {
            $.post('/g-admin/lotterySwitch', {'switch': state}, function(resp) {
                if (resp.code != 0) {
                    alert(resp.msg);
                    $(this).bootstrapSwitch('state', !state, true);
                }
            });
        } else {
            $(this).bootstrapSwitch('state', !state, true);
        }
    });
</script>
</body>
</html>
